package com.hmall.search.mq;

import com.alibaba.fastjson.JSON;
import com.hmall.common.dto.Item;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SpringRabbitListener {
    @Autowired
    SearchService searchService;
    @RabbitListener(queues = "item.queue")
    public void listenSimpleQueueMessage1(String msg) throws InterruptedException {
        System.out.println("listenSimpleQueueMessage1 消费者接收到消息：【" + msg + "】");
        Item item = JSON.parseObject(msg, Item.class);
        log.info("mq消息:{}",item);
            searchService.upOrDown(item);
    }
}